#include<bits/stdc++.h>
using namespace std;
#define nn first
#define cc second
int t;
int d[100005], v[100005], a[100005], p[100005];
int cntt[100005];
bool ll[3005][3005];
pair<int, int> pp[100005];
long long cal_v(int v0, int a, int s){
    long long ret=v0*v0+2*a*s;
    return ret;
}
bool cmp(pair<int, int> a, pair<int, int> b){
    return (a.cc<=b.cc);
}
int main(){
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    scanf("%d", &t);
    int n, m, l, vm, cnt, ans, f;
    long long vmx;
    while(t--){
        scanf("%d%d%d%d", &n, &m, &l, &vm);
        vmx=vm*vm;f=1;cnt=0;
        int f1=1, f2=1;
        for(int i = 1; i <= n; i++){
            scanf("%d%d%d", &d[i], &v[i], &a[i]);
            if(a[i]) f=0;
            if(a[i]<0) f1=0;
            if(a[i]>0) f2=0;
        }
        for(int i = 1; i <= m; i++){
            scanf("%d", &p[i]);
            pp[i].nn=i;pp[i].cc=0;
        }
        if(f){
            for(int i = 1; i <= n; i++){
                if(v[i]>vm && d[i]<=p[m]){
                    cnt++;
                }
            }
            if(cnt) printf("%d %d\n", cnt, m-1);
            else printf("0 %d\n", m);
        }
        else if(f1){
            long long vn;
            for(int i = 1; i <= n; i++){
                f=0;
                if(a[i]<=0){
                    if(v[i]<vm) f=-1;
                }
                for(int j = 1; j <= m && f!=-1; j++){
                    if(d[i]>p[j]) continue;
                    vn=cal_v(v[i], a[i], p[j]-d[i]);
                    if(vn>vmx){
                        f=1;
                    }
                    if(vn<=0) break;
                }
                if(f==1) cnt++;
            }
            printf("%d %d\n", cnt, m-1);
        }
        else{
            long long vn;
            for(int i = 1; i <= n; i++){
                f=0;
                if(a[i]<=0){
                    if(v[i]<vm) f=-1;
                }
                for(int j = 1; j <= m && f!=-1; j++){
                    if(d[i]>p[j]) continue;
                    vn=cal_v(v[i], a[i], p[j]-d[i]);
                    if(vn>vmx){
                        f=1;
                        ll[i][j]=1;
                        pp[j].cc++;
                        cntt[i]++;
                    }
                    if(vn<=0) break;
                }
                if(f==1) cnt++;
            }
            ans=0;
            sort(pp+1,pp+m+1,cmp);
            for(int j = 1; j <= m; j++){
                if(!pp[j].cc){
                    ans++;continue;
                }
                f=1;
                for(int i = 1; i <= n; i++){
                    if(ll[i][pp[j].nn] && cntt[i]==1){
                        f=0;break;
                    }
                }
                if(f){
                    ans++;
                        for(int i = 1; i <= n; i++){
                        if(ll[i][pp[j].nn]){
                            cntt[i]--;
                        }
                    }
                }
            }
            printf("%d %d\n", cnt, ans);
            for(int i = 1; i <= n; i++){
                cntt[i]=0;
                for(int j = 1; j <= m; j++){
                    ll[i][j]=0;
                }
            }
        }
    }
    return 0;
}
